<?php 
class Model_User extends ZloY_Model_CRUD
{
	public function getTable()
	{
		return new Model_DbTable_User();
	}
	
	public function authenticate($login, $password)
	{
		$db = Zend_Registry::get('db');
		$authAdapter = new Zend_Auth_Adapter_DbTable($db);
		
		$authAdapter->setTableName('user');
        $authAdapter->setIdentityColumn('login');
        $authAdapter->setCredentialColumn('password');
        $authAdapter->setIdentity($login);
        $authAdapter->setCredential(md5($password));
        $auth = Zend_Auth::getInstance();
        $result = $auth->authenticate($authAdapter);
	    if($result->isValid()){
            $data = $authAdapter->getResultRowObject(null, 'password');
            $auth->getStorage()->write($data);
            return  true;
        } else {
            return false;
        }
	}
}
?>